import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.zookeeper.CreateMode;

import java.util.concurrent.CountDownLatch;

/**
 * @author wufei
 * @date 2018/3/14/014 16:44
 */
public class CuratorEvenDemo {

    public static void main(String[] args) throws Exception {
        CuratorFramework framework = CuratorUtils.getInstance();
        framework.start();

        PathChildrenCache cache = new PathChildrenCache(framework,"/cruator",true);
        cache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        cache.getListenable().addListener((framework1,pathChildrenCacheEvent)->{
            switch (pathChildrenCacheEvent.getType()){
                case CHILD_ADDED:
                    System.out.printf("CHILD_ADDED");
                    break;
                case CHILD_UPDATED:
                    System.out.printf("CHILD_UPDATED");
                    break;
                case CHILD_REMOVED:
                    System.out.printf("CHILD_UPDATED");
                    break;
                default:
                    break;

            }
        });

        framework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/cruator/n1");
        System.in.read();
    }
}
